<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/7 0007
 * Time: 15:27
 */

namespace app\currency\queue;

use app\wechat\service\WechatService;
use think\console\Input;
use think\console\Output;

/**
 * 微信模板消息 消息队列
 * Class WechatTemplateMessageQueue
 * @package app\currency\queue
 */
class WechatTemplateMessageQueue
{
    /**
     * 当前类名
     * @var string
     */
    const URI = self::class;

    /**
     * sysqueue("模板消息说明", self::URI, 0, ['appid' => $this->appid], 1);
     * @param Input $input
     * @param Output $output
     * @param array $data
     * @throws \WeChat\Exceptions\InvalidResponseException
     * @throws \WeChat\Exceptions\LocalCacheException
     */
    public function execute(Input $input, Output $output, array $data = [])
    {
        $template = [
            'touser' => $data['openid'],//用户openid
            'template_id' => $data['template_id'],//模板ID
            'url' => $data['url'],//跳转网址
            'data' => [
                'first' => ['value' => '恭喜你购买成功！','color' => '#173177'],
                'keyword1' => ['value' => '巧克力','color' => '#173177'],
                'keyword2' => ['value' => '39.8元','color' => '#173177'],
                'keyword3' => ['value' => '2014年9月22日','color' => '#173177'],
                'remark' => ['value' => '欢迎再次购买！','color' => '#173177'],
            ]
        ];
        WechatService::WeChatTemplate()->send($template);
    }
}